<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function toMoneyStr(str) {
        var arr1 = []
        var arr = str.split('').reverse()
        for (let i in arr) {
            s++
            arr1.push(arr[i])
            if (s % 3 == 0) {
                s = 0
                arr1.push(',')
            }
        }
        return arr1.reverse().join('')
    }
    var s = 0
    var str = '1234567'
    var arr2 = toMoneyStr(str)
    console.log(arr2);
</script>
